//
// Created by Administrator on 2021/11/4.
//

#include "ConeBufferGeometry.h"

ConeBufferGeometry::ConeBufferGeometry(const float radius, const float height, const int heightSegments,
                                       const int widthSegments) {
    type = GET_CLASS(__FILE__);
    name = type + "_" + id;

    this->radius = radius;
    this->height = height;
    this->heightSegments = heightSegments;
    this->widthSegments = widthSegments;
}

void ConeBufferGeometry::onInit() {

    polygonMode = GL_LINE;
    drawMode = GL_LINES;

    // 添加圆锥的片段
    for (int i = 0; i < widthSegments; ++i) {
        float u = i / (float) widthSegments;
        float angle = u * M_PI * 2;
        float x = cos(angle);
        float y = sin(angle);
        //vertices.push(x, y, 0);
        vertices.push_back(x);
        vertices.push_back(y);
        vertices.push_back(0);
    }

    BufferGeometry::onInit();
}

void ConeBufferGeometry::drawUI() {
    BufferGeometry::drawUI();

    bool refreshAttri = false;
    if(ImGui::SliderInt("HeightSegments", &heightSegments, 1, 50)){
        refreshAttri = true;
    }
    if(ImGui::SliderInt("WidthSegments", &widthSegments, 3, 50)) {
        refreshAttri = true;
    }

    if(refreshAttri){
        onInit();
    }
}


